<template>
	<view class="pay-number">
		<view>
			<text>本月累计购买</text>
			<text>¥2999</text>
		</view>
		<view>
			<text>总累计购买</text>
			<text>¥2999</text>
		</view>
	</view>

	<view class="order" v-for="item in list">
		<view class="state">
			<text>{{timeFormat(item.created_at, 'yyyy-mm-dd hh:MM:ss')}}</text>
			<text>已完成</text>
		</view>
		<view class="info">
			<image src="/static/order-icon.png" mode=""></image>
			<view class="title">
				<text>{{item.oli_json_data.oli_title}}</text>
				<text>订单号：{{item.order_code}}</text>
			</view>
			<view class="money">
				<text class="red">-¥{{item.price}}</text>
				<text>实付：{{item.price}}</text>
			</view>
		</view>
	</view>
	<view class="nothing" v-if="show && !list.length">
		<image src="/static/nothing-text.png" mode=""></image>
		<text>暂无订单~~</text>
	</view>
</template>

<script setup>
	import { timeFormat } from '@/uni_modules/uview-plus';
	import { onLoad } from '@dcloudio/uni-app'
	import api from '../../api/api';
	import { reactive, ref } from 'vue';

	onLoad(() => {
		oli_orders()
	})

	const list = reactive([])
	const show = ref(false)

	function oli_orders() {
		api.user.oli_orders().then(res => {
			Object.assign(list, res.data.data)
			list.forEach(x => x.oli_json_data = JSON.parse(x.oli_json_data))
			show.value = true
		})
	}
</script>

<style lang="scss">
	.pay-number {
		display: flex;
		align-items: center;
		padding: 36rpx 32rpx;
		color: #bebebe;
		font-size: 28rpx;
		font-weight: 600;

		view {
			>text:nth-child(2) {
				color: #333333;
				font-size: 28rpx;
				margin-left: 10rpx;
			}
		}

		>view:nth-child(1) {
			margin-right: 32rpx;
		}
	}

	.order {
		width: 686rpx;
		background: #FFFFFF;
		border-radius: 12rpx;
		margin: 0 auto 32rpx;
		padding: 20rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;

		.state {
			display: flex;
			justify-content: space-between;
			font-weight: 400;
			font-size: 28rpx;
			color: #BEBEBE;
		}

		.info {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 20rpx;

			>image {
				width: 48rpx;
				height: 48rpx;
			}

			view {
				display: flex;
				flex-direction: column;
				font-weight: 600;
				font-size: 28rpx;

				>text:nth-child(2) {
					font-weight: 400;
					font-size: 24rpx;
					color: #AAAAAA;
					margin-top: 10rpx;
				}
			}

			.red {
				text-align: right;
				color: #D31403;
			}

			.title {
				width: 60%;
			}
		}
	}

	.nothing {
		display: flex;
		align-items: center;
		flex-direction: column;
		font-weight: 400;
		font-size: 28rpx;
		color: #AAAAAA;
		margin-top: 150rpx;

		image {
			width: 276rpx;
			height: 252rpx;
			margin-bottom: 32rpx;
		}
	}
</style>